package cn.tedu.micro.demo.rabbit.amqp;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * 当前项目准备的rabbitmq的消费入口
 */
@Component
@Slf4j
public class AmqpConsumer {
    //消费方法 每当监听绑定一个队列 就需要一个方法实现消费
    /*@RabbitListener(queues= "demo_queue")
    public void consume01(String msg){
        //msg就是当初发送时封装的消息体
        log.info("收到msg:"+msg);
    }*/
    /*@RabbitListener(queues= "demo_queue")
    public void consume02(Message message){
        //1.拿到消息体
        byte[] body = message.getBody();
        //2.拿到消息属性
        MessageProperties messageProperties = message.getMessageProperties();
        //msg就是当初发送时封装的消息体
        log.info("收到msg:"+new String(message.getBody()));
    }*/
    /*@RabbitListener(queues= "demo_queue")
    public void consume03(Channel channel){
        //msg就是当初发送时封装的消息体
        log.info("拿到底层channel:"+channel);
    }*/
    @RabbitListener(queues= "demo_queue")
    public void consume04(String msg, Message message, Channel channel){
        //依次打印入参内容
        log.info("msg:"+msg);
        log.info("message:"+message);
        log.info("channel:"+channel);
    }
    //单独创建方法 监听延迟死信队列
    @RabbitListener(queues= "dlx_q")
    public void consumeDelay(String msg){
        log.info("拿到延迟消息:"+msg);
    }
}
